#include <sys/wait.h>
#include <stdlib.h>
#include <unistd.h>
#include <stdio.h>

int childProcess(int i)
{
    sleep(1);
    printf("child %d\n", i);
    return 0;
}
int main()
{
    pid_t pid;
    int i = 1;
    int status = 0;
    pid = fork();
    if (0 == pid)//子进程
    {
        childProcess(i);
        exit(0);
    }
    //父进程
    // else
    // {
        i += 10;
        printf("father:%d\n", i);
    // }
    /*//By man page
    do
    {
        // i = waitpid(pid, &status, WUNTRACED);
        i = waitpid(-1, &status, WUNTRACED);
        if (i == -1)
        {
            perror("waitpid");
            exit(EXIT_FAILURE);
        }

        if (WIFEXITED(status))
        {
            printf("exited, status=%d\n", WEXITSTATUS(status));
        }
        else if (WIFSIGNALED(status))
        {
            printf("killed by signal %d\n", WTERMSIG(status));
        }
        else if (WIFSTOPPED(status))
        {
            printf("stopped by signal %d\n", WSTOPSIG(status));
        }
        else if (WIFCONTINUED(status))
        {
            printf("continued\n");
        }
    } while (!WIFEXITED(status) && !WIFSIGNALED(status));
    exit(EXIT_SUCCESS);*/
    while (-1 != waitpid(-1, &status, WUNTRACED))
        ;
    exit(EXIT_SUCCESS);
}